package com.cn.camundaappliction.service.impl;

import com.cn.camundaappliction.service.TaskService;
import org.camunda.bpm.engine.RepositoryService;
import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.repository.ProcessDefinition;
import org.camunda.bpm.engine.runtime.ProcessInstance;
import org.camunda.bpm.engine.task.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TaskServiceImpl implements TaskService {

    @Autowired
    private RuntimeService runtimeService;


    @Autowired
    private RepositoryService repositoryService;

    @Autowired
    private org.camunda.bpm.engine.TaskService taskService;

    /**
     * 开启流程定义的方式
     */
    @Override
    public void startProcess(String key) {
        ProcessInstance instance = runtimeService.startProcessInstanceById(key);
        System.out.println(instance.toString());
    }

    /**
     * 查询流程定义
     * @return
     */
    @Override
    public List<ProcessDefinition> findProcess() {
        List<ProcessDefinition> list = repositoryService.createProcessDefinitionQuery().list();
        System.out.println(list.toString()+"xxxxxx");
        return list;
    }

    /**
     * 查询没有完成的任务
     * @return
     */
    @Override
    public List<Task> findTasks() {
        return taskService.createTaskQuery().list();
    }
}
